const start = Date.now()
var generatorPromise = (time) => function () {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      console.log('promise==>',time, Date.now() - start)
      resolve()
    }, time);
  })
}

let list = [generatorPromise(300), generatorPromise(600), generatorPromise(900), generatorPromise(1200)]

let count = 0
let task = []
async function run() {
  if (list.length > 0) {
    while (count < 2) {
       let fn = list.shift()
      count++
      fn().then(() => {
        count--
        run()
      })
    }
  }
}
run()
